using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using CoreManager.Models.Enums;

namespace CoreManager.Models.Entities
{
    /// <summary>
    /// 菜单实体类
    /// </summary>
    [Table("sys_menu")]
    public class Menu : BaseEntity
    {
        /// <summary>
        /// 菜单名称
        /// </summary>
        [Required]
        [MaxLength(100)]
        [Column("name")]
        public string Name { get; set; } = string.Empty;

        /// <summary>
        /// 菜单标识/路由名称
        /// </summary>
        [Required]
        [MaxLength(100)]
        [Column("key")]
        public string Key { get; set; } = string.Empty;

        /// <summary>
        /// 菜单路径
        /// </summary>
        [MaxLength(200)]
        [Column("path")]
        public string? Path { get; set; }

        /// <summary>
        /// 菜单图标
        /// </summary>
        [MaxLength(100)]
        [Column("icon")]
        public string? Icon { get; set; }

        /// <summary>
        /// 父级菜单ID
        /// </summary>
        [Column("parent_id")]
        public int? ParentId { get; set; }

        /// <summary>
        /// 菜单类型 (1:目录 2:菜单 3:按钮)
        /// </summary>
        [Column("type")]
        public int Type { get; set; } = 2;

        /// <summary>
        /// 排序号
        /// </summary>
        [Column("sort")]
        public int Sort { get; set; } = 0;

        /// <summary>
        /// 是否隐藏
        /// </summary>
        [Column("hidden")]
        public bool Hidden { get; set; } = false;

        /// <summary>
        /// 组件路径
        /// </summary>
        [MaxLength(200)]
        [Column("component")]
        public string? Component { get; set; }

        /// <summary>
        /// 页面标题
        /// </summary>
        [MaxLength(100)]
        [Column("title")]
        public string? Title { get; set; }

        /// <summary>
        /// 面包屑隐藏
        /// </summary>
        [Column("breadcrumb_hidden")]
        public bool BreadcrumbHidden { get; set; } = false;

        /// <summary>
        /// 标签页可关闭
        /// </summary>
        [Column("closable")]
        public bool Closable { get; set; } = true;

        /// <summary>
        /// 缓存页面
        /// </summary>
        [Column("keep_alive")]
        public bool KeepAlive { get; set; } = false;

        /// <summary>
        /// 固定标签页
        /// </summary>
        [Column("affix")]
        public bool Affix { get; set; } = false;

        /// <summary>
        /// 菜单状态 (1:启用 0:禁用)
        /// </summary>
        [Column("status")]
        public int Status { get; set; } = 1;

        /// <summary>
        /// 菜单描述
        /// </summary>
        [MaxLength(500)]
        [Column("description")]
        public string? Description { get; set; }

        /// <summary>
        /// 权限标识
        /// </summary>
        [MaxLength(200)]
        [Column("permission")]
        public string? Permission { get; set; }

        // 导航属性

        /// <summary>
        /// 父级菜单
        /// </summary>
        [ForeignKey("ParentId")]
        public virtual Menu? Parent { get; set; }

        /// <summary>
        /// 子菜单列表
        /// </summary>
        public virtual ICollection<Menu> Children { get; set; } = new List<Menu>();
    }
}